<?php
/**
 * Enter description here...
 *
 * @package util.db.drivers
 * @since 0.2
 */
abstract class IAbstractDbDriver extends IObject implements IDbDriver {
	protected $config = array();
	
	/**
	 * Enter description here...
	 * 
	 * $config = array(
	 *   dbname, username, password, host, port, persistent, charset
	 * );
	 *
	 * @param array $config
	 */
	public function __construct(array $config) {
		$this->config = $config;
		$this->checkRequiredOptions();
	}
	
	public function configs() {
		return $this->config;
	}
	
	public function config($option) {
		if (array_key_exists($option, $this->config)) {
			return $this->config[$option];
		}
		return null;
	}
	
	private function checkRequiredOptions() {
		$required = array("host", "dbname", "username", "password");
		foreach ($required as $option) {
			if (!array_key_exists($option, $this->config)) {
				throw new IDbException("can not find '{$option}' in db config");
			}
		}
	}
	
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $sql
	 * @param unknown_type $params
	 * @return IDbStatement
	 */
	public function prepare($sql, $params = array()) {
		return new IDbStatement($this, $sql, $params);
	}
}

?>